package com.dataexa.ky.core.utils.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: Michael
 * @Date: 2020/3/28 11:19 下午
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResultDto<T> {
    @JsonProperty("code")
    private String code;
    @JsonProperty("msg")
    @Builder.Default
    private String msg = "success";
    @JsonProperty("data")
    private T data;

    public ResultDto(T data) {
        this.code = "0";
        this.msg = "success";
        this.data = data;
    }

    public static ResultDto error(String code , String msg) {
        return ResultDto.builder().code(code).msg(msg).data(null).build();
    }
    public static ResultDto error(String msg) {
        return ResultDto.builder().code("-1").msg(msg).data(null).build();
    }
    public static <K> ResultDto<K> success(K data) {
        return ResultDto.<K>builder().code("0").msg("success").data(data).build();
    }
}
